#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#define N 1000

int main()
{
	int n = 0;
	scanf("%d", &n);

	int i = 0;
	int j = 0;
	int count = 0;
	char c[N];
	for (i = 1; i <= n; i++)
	{
		scanf("%s", c);
		for (j = 0; c[j] != '\0'; j++)
		{
			if (c[j] >= '0' && c[j] <= '9')
				count++;
		}
		printf("%d\n", count);
		count = 0;
	}
	return 0;
}